# -*- coding: utf-8 -*-
# @Time    : 2021/5/5 16:01
# @Author  : Chen
# @Email   : 2356458272@qq.com
# @File    : 03.py
# @Software: PyCharm
import random
class User():
    money = 100
    def __init__(self,name,sex):
        self.name = name
        self.sex = sex
        self.ph = 100
        self.room = None
        self.zb = None
    # def zb_add(self):
    def attack(self,other):
                if other.zb:
                    other.ph = other.ph - 5
                    print(f"{other.name}装备了装备抵御了{self.name}五点攻击")
                    if other.ph <= 0:
                        print(f"{self.name}赢了,剩余ph{self.ph}战斗结束")
                else:
                    other.ph = other.ph-10
                    if other.ph <= 0:
                        print(f"{self.name}赢了,剩余ph{self.ph}战斗结束")





class Home():
    def __init__(self,homename):
        self.home_name = homename
        self.member = []
    def home_add(self,user):
        if user.room == None:
            if len(self.member) < 2:
                self.member.append(user)
                user.room = self.home_name
                print(f"{user.name}成功加入{self.home_name}房间")
        else:
            print(f'你已经加入过{user.room}房间了,如果想加入此房间，请先退出{user.room}')
            a = input('退出请输入1：')
            if int(a) == 1:
                home[user.room].member.remove(user)
                user.room = None
                print("退出成功")



user = dict()
#用户，value是实例化对象
home = dict()
#房间，value是实例化对象
# name  = input('请输入：')
# sex = input()
# user['cz'] = User('cz','n')
# print(user['cz'].money)
# user['c'] = User('c','n')
# print(user['c'].money)
# print(user)
while 1:
    a = int(input("请输入1-5："))
    if a == 1:
        name,sex = input("请输入name,sex：").split()
        user[name]=User(name,sex)
    elif a == 2:
        home_name = input("请输入home_name：")
        home[home_name] = Home(home_name)
    elif a == 3:
        # print(user,home)
        name, home_name = input("请输入您要加入的角色和房间名，空格分隔:\n").split()
        home[home_name].home_add(user[name])
    elif a == 4:
        print("开始战斗")
        home_name = input("请输入战斗的房间号：")
        if len(home[home_name].member) < 2:
            print(f"{home_name}人员不足")
        else:
            while 1:
                if home[home_name].member[1].ph > 0 and home[home_name].member[0].ph > 0:
                    b = random.choice([0,1])
                    c = random.choice([0, 1])
                    if b == 0:
                        if c == 0:
                            home[home_name].member[1].zb = 1
                        home[home_name].member[0].attack(home[home_name].member[1])
                    else:
                        if c == 0:
                            home[home_name].member[0].zb = 1
                        home[home_name].member[1].attack(home[home_name].member[0])
                else:
                    break
    else:
        break

